Homework solutions will be graded on the following criteria:
All code should be written individually by the student, unless otherwise specified in the HW. Students are encouraged to work together, but sharing code is a violation of academic integrity.
File Format: turn in an .ipynp notebook file to NoteBowl. The name should be lastname_firstname_hw4.ipynb. For example:
hopper_grace_hw4.ipynp
Your notebook should be neatly formatted, with a heading (including your name, the assignment, the class, the date) and appropriate use of Markdown cells alongside code cells.
Time for some modelling, y’all!
Uh, I meant mathematical models!
Buying a house is the biggest financial decision most Americans (or humans of any nationality) will make. In order to finance the purchase, most folks will need to take out a loan. Loans for property are called “mortgages”. These loans use an interest schedule known as “amortization”:
Thus “amortization” literally means “to make it dead”, or “to kill it off”. Isn’t that nice?
The mechanics of amortized amortized loans are quite simple, but the choices that buyers make can have dramatic implications for the total amount of money they spend (and also the time it takes to pay the loan). For context, most Americans choose a 30-year amortization schedule – that’s most of your working life!
In this HW, you’ll write a computer model to investigate these considerations. First, let’s establish some terminology:
closing price is the amount of money that the property sells for. It’s called that because the process of finalizing a mortgage is called “closing”.down payment is the amount of money that the property buyers pay immediately upon purchase. In this way, buyers pay a portion of the total closing price immediately upon purchase, and the rest is payed on a loan schedule.The principal is the amount of money that property buyers need to borrow in order to buy the property. Upon purchase, the principal is easy to calculate:
principal = closing price - down payment
In other words, this is the debt that home buyers have to begin with upon purchasing their property.
Each month, the principal gets smaller as owners pay off the debt.
The APR, or Annual Percentage Rate, is the interest rate that homeowners are charged for their loan. Generally this rate is somewhere between 2% - 6%. Important Note Interest is added to the loan on a monthly basis. See details right below.
The interest is the finance charge added to the balance. It’s based on the APR. Each month, the interest is calculated by the following model:
interest = principal*apr/12
The payment is the amount that buyers pay each month for their loan. Each month, the payment will first pay off the interest accrued, and the remainder will go to the principal.
Thus, each month, the principal is decreased by the following formula:
principal = principal - (payment - interest)
Students must write a script, in one code cell at the beginning of the notebook, that includes the following functions:
monthlyPayment() [arguments up to you] should take as input the current principal, payment, and apr. It should return as output a list of the following:
principal,interest paid that month, andpayment - interest)paymentHistory() [arguments up to you] should take as input the closing price, the down payment, the apr, and the monthly payments. This function should use a loop to calculate the balance each month for the duration of the loan (until the balance is zero) using the monthlyPayment() function. It should return as output a list of the following:
printRecords() [argument up to you] should take as input the results of your paymentHistory() function, and print the following on a row-by-row (ie month-by-month) basis to the console:
plotTotals() should take as input the results of your paymentHistory() function, and use the matplotlib library to plot the following monthly TOTALS:
main() should control the action as usual. Your main() function should prompt the user for the following input:
closing pricedown paymentaprmonthly paymentsprintRecords or plotTotals functions should be called.All functions must have an accompanying docstring explaining their purpose, the inputs, and the outputs.
For partial credit, use comments to exlain what your code does.
Below your code for the above model, use additional code cells to actually run the model you wrote above. In particular, you should experiment with:
down paymentaprpaymentUsing Markdown cells, discuss:
Be creative. Play around with your model. Have fun!
As usual, the assignment description lays out the minimum qualifications. You don’t have to get it 100% right to pass, you just need to show me your thoughts and ideas. Your code must actually run in order to earn a passing grade, but know that I’ll give you partial credit for making it part of the way to the complete assignment.
To earn an A, students must implement all functionality as described above, in good clear style with documentation.
You may find opportunities to improve upon the output and structure of the program. Be sure your work satisfies the minimum requirements, but feel free to expand upon these and to exercise your creativity. I enjoy reading your work, and maybe there’s a stoic nod from Prof Miller in your future. ;D
File Format: turn in a .py script file to NoteBowl. The name should be lastname_firstname_hw3.py. For example:
lovelace_ada_hw3.py
This HW will focus on the turtle library discussed in class. The goal of the program is to allow the user to create shape patterns based on their input.
Your script should contain the following functions:
makeSquare(tortise, heading, x, y, length, fillColor)
tortise will be a turtle object,heading is the initial heading in degrees \((0^\circ=\) due east and \(180^\circ=\) due west, as in a circle\()\),x and y are the lower-left coordinates of the square,length is the side length of the square, andfillColor is the color that will be filled in the square. You may assume that the input either one of the valid, built-in color strings or a hex tuple (see p74 of your text).shape() function.makeTriangle, a similar function called that takes the same arguments but draws triangles. Do not use the built-in shape() function.
spread (arguments are up to you) This function should be able to make a “spread” of either squares or triangles (depending on input). See example picture below. Details not specified here are up to you. Choose wisely.
zoom (arguments up to you) This function should make a “zoom” of squares or triangles (depending on input). See picture below. Details not specified here are up to you. Choose wisely.slide (arguments up to you) This function should slide an input shape, either squares or triangles. See picture below. Details not specified here are up to you. Choose wisely.A main() function that controls the logic of the program.
input() function to prompt the user for the following:
Grading:
makeSquare, makeTriangle, and main functions without errors and according to the specifications, along with the docstring.spread, zoom, or slide functions, then they can earn a max grade of B.File Format: turn in the .ipynb file for your notebook. Name it with this format:
Lastname_Firstname_HW3.ipynb
So, if I was a student, I’d turn in:
Miller_Alice_HW3.ipynb
Problems:
2.3.4
In class on Friday Sept 04, we wrote a for loop to assign each employee in a list of employees a day of the week to work on.
Your HW problem is to extend this program in the following way:
input() function. There are many reasonable ways to go about this.There are two acceptable outputs:
Your program can print out the schedule in the same way we did in Lecture. A correct solution like this will earn a maximum of 92% credit for this problem.
[['Ali, Fred'], ['Ben', 'Greg'], ['Charles', 'Helen'], ['Deb', 'Ian'], ['Ellie', 'Jack']]
File format: Problems should be completed in a Jupyter Labs notebook, exported to html (we’ll talk about this in class). The .html file should be submitted to NoteBowl under the HW 1 assignment.
Each solution should be written in a separate Markdown cell, showing the problem number with a header (you can make a header by starting the line with “#”).
The first cell of the notebook should have a header for the title of the assignment (CS 111 HW 1), and your name.
The problems for this HW come from the text:
All of these problems should be solved in clear, concise English sentences (or lists). No code here.